require('../conf/dbInit').init();
var config = require('../conf/config')
    , fs = require('fs')
    , async = require("async")
    , _ = require('underscore');

global.client_id = '3799249803934DE99495C9584AE68449';
global.client_secret = 'F07B8035741F42D7A0D7F6F71F98CB1A';

/**
 * 最终测试执行方法
 *
 * @param callbackFuns  可以为回调函数数组或是类似java的可变参
 * <pre>
 *     exec(fun1, fun2, fun3);
 *   或
 *     exec([fun1, fun2, fun3]);
 * </pre>
 *
 */
exports.exec = function (callbackFuns) {
    var callbacks = _.isArray(callbackFuns) ? callbackFuns : arguments;
    async.each([config.logPath], function (path, callback) {
        fs.readdir(path, function (err, result) {
            if (err) {
                console.info('正初始文件目录：%s', path);
                fs.mkdir(path, function (_err) {
                    callback(_err);
                });
            } else {
                callback(err);
            }
        });
    }, function (err) {
        if (err) {
            console.error('初始化工程目录出错：%s', err);
        } else {
            require('../conf/logs').init();
            _.each(callbacks, function (callback) {
                callback();
            });
        }
    });
};